//---------------------------------------------------------------------------

#ifndef PubDefineH
#define PubDefineH
//---------------------------------------------------------------------------
#include <list>
#ifndef WIN32
	#include <sys/socket.h>
	#include <netinet/in.h>
#else
	#include <winsock.h>
#endif
#include <QString>
#define IPTOSBUFFERS    12
#include <stdio.h>
#define ASCII_LINELENGTH 300
#define HEXDUMP_BYTES_PER_LINE 16
#define HEXDUMP_SHORTS_PER_LINE (HEXDUMP_BYTES_PER_LINE / 2)
#define HEXDUMP_HEXSTUFF_PER_SHORT 6 /* 4 hex digits and 2 space */
#define HEXDUMP_HEXSTUFF_PER_LINE \
		(HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE)
#define	ETHERTYPE_IP		0x0800	/* Ethernet IP protocol */
#define ETHERTYPE_ARP   0x0806 //
#define EARP 55;
#define	ETHERTYPE_PPPOE_SESSION		0x8864	/* Ethernet pppoe session */
#define MAXCAPMESSAGE 6190

/*
 * The number of bytes in an ethernet (MAC) address.
 */
#define	ETHER_ADDR_LEN		6
/*
 * Length of a DEC/Intel/Xerox or 802.3 Ethernet header; note that some
 * compilers may pad "struct ether_header" to a multiple of 4 bytes,
 * for example, so "sizeof (struct ether_header)" may not give the right
 * answer.
 */

/*
 * Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
 */
/* 4 bytes IP address */
typedef struct ipaddress{
	u_char byte1;
	u_char byte2;
	u_char byte3;
	u_char byte4;
}ip_address;

typedef struct	etherheader {
	u_char	ether_dhost[ETHER_ADDR_LEN];
	u_char	ether_shost[ETHER_ADDR_LEN];
	u_short	ether_type;
}ether_header;

typedef struct pppoeheader
{
u_char ver_type;
u_char code;
u_short session_id;
u_short length;
} pppoe_header;
typedef struct ppheader
{
u_short proto;
}pp_header;


/* IPv4 header */
typedef struct ipheader{
    u_char  ver_ihl;        // Version (4 bits) + Internet header length (4 bits)
    u_char  tos;            // Type of service
    u_short tlen;           // Total length
    u_short identification; // Identification
    u_short flags_fo;       // Flags (3 bits) + Fragment offset (13 bits)
    u_char  ttl;            // Time to live
    u_char  proto;          // Protocol
    u_short crc;            // Header checksum
	ip_address  saddr;      // Source address
    ip_address  daddr;      // Destination address
    u_int   op_pad;         // Option + Padding
}ip_header;

/* UDP header*/
typedef struct udpheader{
    u_short sport;          // Source port
    u_short dport;          // Destination port
    u_short len;            // Datagram length
    u_short crc;            // Checksum
}udp_header;

typedef struct tcpheader             //定义TCP首部
{   u_short sport;               //16位源端口
    u_short dport;               //16位目的端口
    u_long th_seq;         //32位序列号
    u_long th_ack;         //32位确认号
    u_char th_lenres;        //4位首部长度/6位保留字
    u_char th_flag;            //6位标志位
    u_short th_win;                 //16位窗口大小
	u_short th_sum;                 //16位校验和
    u_short th_urp;                 //16位紧急数据偏移量
}tcp_header;


typedef struct nodedata
{
char starttime[16];
int ip_header_len;
int udp_header_len;
int tcp_header_len;
ip_address srcip;
u_short sport;
ip_address dstip;
u_short dport;
u_char proto;
u_short packscount;
char lasttime[16];
struct pcap_pkthdr *header;
void* srcpackdata; //原始包数据
u_int srcpacksize; //原始包长度
u_int datasize; //数据长度
void* next;
std::list<const nodedata*> childs;
long listitemindex;
bool ip_flag;
bool pppoe_flag;
bool udp_flag;
bool tcp_flag;
int up_or_down; //0 up,1 down;
bool isroot;
} nodedata;
//int iptos(const ip_address ipaddress);
#define ETHER_HDRLEN		14
#define PPPOE_HDRLEN		8
#define UDP_HDRLEN			8
//#define TCP_HDRLEN			20




#endif
